package com.gxa.modules.service.impl;

import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.InventoryMapper;
import com.gxa.modules.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired(required = false)
    private InventoryMapper inventoryMapper;

    @Override
    public ResultVo queryInventory(Integer sh_id, Integer currentPage, Integer pageSize) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> inventory = inventoryMapper.queryInventory(sh_id,currentpage1,pageSize);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(inventory);
        return resultVo;
    }

    @Override
    public ResultVo queryGoodstores(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> goodstores = inventoryMapper.queryGoodstores(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(goodstores);
        return resultVo;
    }

    @Override
    public ResultVo queryCargoStorage(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> cargoStorage = inventoryMapper.queryCargoStorage(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(cargoStorage);
        return resultVo;
    }

    @Override
    public ResultVo queryStoresAllocate(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> storesAllocate = inventoryMapper.queryStoresAllocate(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(storesAllocate);
        return resultVo;
    }

    @Override
    public ResultVo queryWareHouseDamage(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> warehouseDamage = inventoryMapper.queryWareHouseDamage(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(warehouseDamage);
        return resultVo;
    }

    @Override
    public ResultVo queryGoodsTable(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> goodsTable = inventoryMapper.queryGoodsTable(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(goodsTable);
        return resultVo;
    }

    @Override
    public ResultVo queryShipmentstorage(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> shipmentstorage = inventoryMapper.queryShipmentstorage(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(shipmentstorage);
        return resultVo;
    }

    @Override
    public ResultVo queryReturnGoods(Integer currentPage, Integer pageSize,Integer sh_id) {
        ResultVo resultVo = new ResultVo();
        Integer currentpage1 = (currentPage-1)*pageSize;
        List<Map> returnGoods = inventoryMapper.queryReturnGoods(currentpage1,pageSize,sh_id);
        resultVo.setCode(200);
        resultVo.setMsg("查询成功");
        resultVo.setData(returnGoods);
        return resultVo;
    }

    @Override
    public ResultVo queryAll(String id) {
        ResultVo resultVo = new ResultVo();
        String[] id1 = id.split("1");
        if(id1[0].equals("YHD")){
            Map goodstores = inventoryMapper.findGoodstores(id);
            resultVo.setData(goodstores);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
        }else if (id1[0].equals("YHRK")){
            Map cargoStorage = inventoryMapper.findCargoStorage(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(cargoStorage);
        }else if (id1[0].equals("DBD")){
            Map storesAllocate = inventoryMapper.findStoresAllocate(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(storesAllocate);
        }else if (id1[0].equals("BSD")){
            Map warehouseDamage = inventoryMapper.findWareHouseDamage(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(warehouseDamage);
        }else if(id1[0].equals("PHD")){
            Map goodsTable = inventoryMapper.findGoodsTable(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(goodsTable);
        } else if (id1[0].equals("PHRK")){
            Map shipmentstorage = inventoryMapper.findShipmentstorage(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(shipmentstorage);
        }else if (id1[0].equals("THD")){
            Map returnGoods = inventoryMapper.findReturnGoods(id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(returnGoods);
        }
        return resultVo;
    }

    @Override
    public ResultVo findAllById(Integer sh_id, String id) {
        ResultVo resultVo = new ResultVo();
        String[] id1 = id.split("1");
        if(id1[0].equals("YHD")){
            List<Map> goodstores = inventoryMapper.findGoodstorescommodity(sh_id,id);
            resultVo.setData(goodstores);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
        }else if (id1[0].equals("YHRK")){
            List<Map> cargoStorage = inventoryMapper.findCargoStoragecommodity(sh_id,id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(cargoStorage);
        }else if (id1[0].equals("DBD")){
            List<Map> storesAllocate = inventoryMapper.findStoresAllocatecommodity(sh_id,id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(storesAllocate);
        }else if (id1[0].equals("BSD")){
            List<Map> warehouseDamage = inventoryMapper.findWareHouseDamagecommodity(sh_id,id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(warehouseDamage);
        }else if (id1[0].equals("PHRK")){
            List<Map> shipmentstorage = inventoryMapper.findShipmentstoragecommodity(sh_id,id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(shipmentstorage);
        }else if (id1[0].equals("THD")){
            List<Map> returnGoods = inventoryMapper.findReturnGoodscommodity(sh_id,id);
            resultVo.setCode(200);
            resultVo.setMsg("查询成功");
            resultVo.setData(returnGoods);
        }
        return resultVo;
    }

    @Override
    public ResultVo updateStatus(Integer sh_id, String id) {
        ResultVo resultVo = new ResultVo();
        String[] id1 = id.split("1");
        if(id1[0].equals("YHD")){
            Integer resoult = inventoryMapper.updateGoodstores(sh_id,id);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("DBD")){
            Integer resoult = inventoryMapper.updateStoresAllocate(sh_id,id);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("PHD")){
            Integer resoult = inventoryMapper.updateShipmentstorage(sh_id,id);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }
        return resultVo;
    }

    @Override
    public ResultVo updateGoods( Map map) {
        ResultVo resultVo = new ResultVo();
        String id2 =(String)map.get("id");
        String[] id1 = id2.split("1");
        if(id1[0].equals("YHD")){
            Integer resoult = inventoryMapper.updateGoodstorescommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("YHRK")){
            Integer resoult = inventoryMapper.updateCargoStoragecommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("DBD")){
            Integer resoult = inventoryMapper.updateStoresAllocatecommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("BSD")){
            Integer resoult = inventoryMapper.updateWareHouseDamagecommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("PHRK")){
            Integer resoult = inventoryMapper.updateShipmentstoragecommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }else if (id1[0].equals("THD")){
            Integer resoult = inventoryMapper.updateReturnGoodscommodity(map);
            if(resoult > 0){
                resultVo.setCode(200);
                resultVo.setMsg("修改成功");
            }
        }
        return resultVo;
    }
}
